Skip to content

o11y(assisted-query): Track error outcomes and reasons for AI query analytics#115699

Merged
aliu39 merged 3 commits into
masterfrom
aliu/error-outcome
May 18, 2026
Merged

o11y(assisted-query): Track error outcomes and reasons for AI query analytics#115699
aliu39 merged 3 commits into
masterfrom
aliu/error-outcome

Conversation

@aliu39
Copy link
Copy Markdown
Member

@aliu39 aliu39 commented May 16, 2026

Summary

Extends trackAiQueryOutcome to emit a new error_on_load outcome (alongside the existing has_results / empty_results) and capture an error_reason attribute when an AI-assisted query's table load fails. Previously, errored queries were silently bucketed as empty_results, conflating empty data with failures.

trackAiQueryOutcome util

  • error param now accepts string | boolean | Error (was string | boolean).
  • New extractErrorReason(err) centralizes reason extraction: for RequestError it pulls responseJSON.detail (handling both string and {message} shapes); for any other Error it falls back to err.message.
  • Emits outcome: 'error_on_load' plus error_reason in the log/metric attributes whenever error is truthy.

Discover errors (views/discover/results.tsx)

  • fetchTotalCount's catch block now calls trackAiQueryOutcome with error: err so failed total-count requests are tracked instead of silently swallowed.
  • aiQueryRunId and mode hoisted above the try so both branches share them.

Explore (views/explore/hooks/useAnalytics.tsx)

Spans, traces, logs, and metrics analytics hooks now pass the raw Error object (instead of a pre-extracted error?.message string) through to trackAiQueryOutcome. The error is boxed with useBox to avoid spurious effect re-fires on error-message identity changes; effect deps include the box ref.

Test plan

  • Trigger a failing query in Explore (spans/logs/metrics) and verify the assisted_query.outcome log/metric records outcome: 'error_on_load' with a populated error_reason.
  • Trigger a 4xx/5xx from events-meta/ in Discover (errors dataset) and verify the same.
  • Confirm successful queries still emit has_results / empty_results correctly.

aliu39 and others added 2 commits May 15, 2026 17:38
Extend trackAiQueryOutcome to emit an `error_on_load` outcome (with an
optional error_reason attribute) when a table result fails to load.
Previously, errored queries were silently bucketed as `empty_results`,
which conflated empty data with failures.

Wire up the new `error` param from spans, logs, and metrics analytics
hooks using the existing tableError values, boxed to avoid extra
effect re-fires.

Co-Authored-By: Claude <[email protected]>
Extend trackAiQueryOutcome's `error` param to accept `Error` (in
addition to `string | boolean`). The util now centralizes reason
extraction: for `RequestError` it pulls `responseJSON.detail`
(handling both string and `{message}` shapes), otherwise it falls
back to `err.message`.

Wire this through in two places:
- Discover errors: add a second trackAiQueryOutcome call in
  fetchTotalCount's catch block so failed total-count requests
  emit an error_on_load outcome with the API reason.
- Explore (spans, traces, logs, metrics): pass the raw `Error`
  object from the table result through useBox to the outcome
  call instead of pre-extracting `error?.message`.

Co-Authored-By: Claude <[email protected]>
@aliu39 aliu39 requested review from a team as code owners May 16, 2026 01:01
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 16, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.53%

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ea54c73. Configure here.

Comment thread static/app/views/explore/hooks/useAnalytics.tsx
@aliu39 aliu39 changed the title feat(explore): Track error outcomes and API reasons for AI queries o11y(assisted-query): Track error outcomes and API reasons for AI queries May 16, 2026
@aliu39 aliu39 changed the title o11y(assisted-query): Track error outcomes and API reasons for AI queries o11y(assisted-query): Track error outcomes and reasons for AI query analytics May 16, 2026
isaacwang-sentry
isaacwang-sentry approved these changes May 18, 2026
@aliu39 aliu39 merged commit cc4a229 into master May 18, 2026
74 checks passed
@aliu39 aliu39 deleted the aliu/error-outcome branch May 18, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants